//
//  UIImage+extension.swift
//  daoge_sineweibo
//
//  Created by 伍禄林 on 16/10/16.
//  Copyright © 2016年 伍禄林. All rights reserved.
//

import Foundation


extension UIImage {
    
    func cz_avaterImage(size: CGSize, background: UIColor = .white,lineColor: UIColor = .lightGray) -> UIImage {
        
        var size = size
        
        if size == nil  {
            size = self.size
        }
        
        let rect = CGRect(origin: CGPoint(), size: size)
        
        UIGraphicsBeginImageContextWithOptions(rect.size, true, 0)
        
        background.setFill()
        
        UIRectFill(rect)
        
        let path = UIBezierPath(ovalIn: rect)
        path.addClip()
        
        draw(in: rect)
        
        let overPath = UIBezierPath(ovalIn: rect)
        
        overPath.lineWidth = 2
        lineColor.setStroke()
        overPath.stroke()
        
        let result = UIGraphicsGetImageFromCurrentImageContext()
        
        UIGraphicsEndImageContext()
        
        return result!
        
    }
    
    
}
